#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int arr[101010] = { 0 };
void fun (int n,int r,int flag)
{
	int i = 0;
	while (n) {
		arr[i++] = n % r;
		n /= r;
	}
	if (flag==0) {
		cout << "-";
	}
	for (int j = i - 1; j >= 0; j--) {
		if (arr[j] >= 0 && arr[j] <= 9) {
			cout << arr[j];
		}
		else if (arr[j] == 10) {
			cout << "A";
		}
		else if (arr[j] == 11) {
			cout << "B";
		}
		else if (arr[j] == 12) {
			cout << "C";
		}
		else if (arr[j] == 13) {
			cout << "D";
		}
		else if (arr[j] == 14) {
			cout << "E";
		}
		else if (arr[j] == 15) {
			cout << "F";
		}
	}
	cout << endl;
}
int main()
{
	int n, r;
	while (cin >> n >> r) {
		bool flag = 1;
		if (n < 0) {
			flag = 0;
			n = (-n);
		}
		fun(n, r,flag);
	}
	return 0;
}